package com.red.pojo;

import com.red.util.HttpStatusUtil;

import java.util.HashMap;

/**
 * 通用返回对象
 */
public class Result extends HashMap<String, Object> {

    private static final String MSG_TAG = "msg";
    private static final String CODE_TAG = "code";
    private static final String DATA_TAG = "data";

    public Result() {
    }

    public Result(int code, String msg, Object date) {
        super.put(MSG_TAG, msg);
        super.put(CODE_TAG, code);
        super.put(DATA_TAG, date);
    }

    public Result(int code, String msg) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
    }

    public static Result success(String msg) {
        return new Result(HttpStatusUtil.SUCCESS, msg);
    }

    public static Result success() {
        return Result.success("操作成功");
    }

    public static Result error(String msg) {
        return new Result(HttpStatusUtil.ERROR, msg);
    }

    public static Result error() {
        return error("操作失败");
    }
}
